//
//  EditNumView.m
//  夺宝吧
//
//  Created by xiaocai on 15/7/24.
//  Copyright (c) 2015年 FangYuan. All rights reserved.
//

#import "EditNumView.h"
//编辑收货地址
#define EDIT_ADD_URL @"/api/ApiUser/editReceivingAddr"
@interface EditNumView ()
{
    __weak IBOutlet UILabel *l1;
    __weak IBOutlet UILabel *l2;
    __weak IBOutlet UILabel *l3;
    
    __weak IBOutlet UIButton *commitBtn;

    __weak IBOutlet UIView *bgView;
    
    __weak IBOutlet UITextField *phoneText;
    __weak IBOutlet UITextField *qqText;
    
    __weak IBOutlet UITextField *zfbText;
    
    //记录
    NSString *_name;
    NSString *_phone;
    NSString *_detail;
}
@end
@implementation EditNumView
-(void)awakeFromNib
{
    bgView.backgroundColor = QBB_GRAY_COLOR;
    commitBtn.layer.cornerRadius = 2;
    commitBtn.layer.masksToBounds = YES;
    commitBtn.backgroundColor = QBB_RED_COLOR;
    CGFloat add = 0;
    [self addSubview:[WYPublic getFenGexian:0 :(CGRectGetMaxY(l1.frame)+add) :WYMWITH :0.5]];
    [self addSubview:[WYPublic getFenGexian:0 :(CGRectGetMaxY(l2.frame)+add) :WYMWITH :0.5]];
    [self addSubview:[WYPublic getFenGexian:0 :(CGRectGetMaxY(l3.frame)+add) :WYMWITH :0.5]];
}

- (IBAction)commitBtnOnClick:(id)sender {
     [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
    if (phoneText.text.length != 0 || qqText.text.length != 0 || zfbText.text.length != 0) {
        NSDictionary *params = @{@"recharge_mobile":phoneText.text,@"recharge_qq":qqText.text,@"recharge_alipay":zfbText.text,@"uid":[UserInfo getUserID],@"token":[UserInfo getUserToken],@"refresh_token":[UserInfo getRefreshToken]};
        
        [WYPublic addZheZhaoToWindowWithTitle:nil];
        [WYRequest startPostForDicWithUrlStR:[NSString stringWithFormat:@"%@%@",DBB_IP,EDIT_ADD_URL] Parameters:params successBlock:^(NSDictionary *dic) {
            NSNumber *ret = dic[@"ret"];
            if (ret.intValue == 0) {
                [WYPublic showMessageWithTitle:@"提示：" Msg:@"保存充值号码成功"];
                if (self.father.isZhongJiangFlag) {
                    [self.father.navigationController popViewControllerAnimated:YES];
//                    [self.father.lastFooter fillNumWithQQ:qqText.text Phone:phoneText.text ZFB:zfbText.text Andtime:dic[@"data"][@"status_time"]];
                }
            }else{
                if(ret.intValue>2000 && ret.intValue < 3000){
                    //用户过期，强制重新登录 先删除用户信息
                    [UserInfo deleteUserInfo];
                    //登录
                    [WYPublic ifUserHaveLogin];
                    [WYPublic showMessageWithTitle:@"提示：" Msg:@"登录信息已过期"];
                }else{
                    [WYPublic showMessageWithTitle:@"错误提示:" Msg:dic[@"msg"]];
                }
                
            }
            [WYPublic removeZheZhaoToWindow];
        } failedBlock:^{
            [WYPublic removeZheZhaoToWindow];
        } needLog:NO];

    }else{
        [WYPublic showMessageWithTitle:@"" Msg:@"录入信息不能全部为空"];
    }
}
//默认信息
- (void)morenInfoWithPhone:(NSString *)phone QQ:(NSString *)qq ZFB:(NSString *)zfb
{
    phoneText.text = [WYPublic getUsefullStr:phone];
    qqText.text = [WYPublic getUsefullStr:qq];
    zfbText.text = [WYPublic getUsefullStr:zfb];
}
@end
